using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    /// <summary> 
    ///Author: nnamthach@gmail.com 
    /// <summary>
    public class LIST_LOOKUPControl
    {
        #region Local Variable
        private LIST_LOOKUPDataAccess _objDAO;
        #endregion Local Variable

        #region Method
        public LIST_LOOKUPControl()
        {
            _objDAO = new LIST_LOOKUPDataAccess();
        }

        public LIST_LOOKUPInfo Get(
        String DTB,
        String LOOKUP_CATEGORY,
        String CODE,
        ref string sErr)
        {
            return _objDAO.Get(
            DTB,
            LOOKUP_CATEGORY,
            CODE,
            ref sErr);
        }
        public DataTable Get_Category(
                String DTB,
                String LOOKUP_CATEGORY,

                ref string sErr)
        {
            return _objDAO.Get_Category(
            DTB,
            LOOKUP_CATEGORY,

            ref sErr);
        }

        public DataTable GetAll(
        String DTB,
        ref string sErr)
        {
            return _objDAO.GetAll(
            DTB,
            ref sErr);
        }

        public Int32 Add(LIST_LOOKUPInfo obj, ref string sErr)
        {
            return _objDAO.Add(obj, ref sErr);
        }

        public string Update(LIST_LOOKUPInfo obj)
        {
            return _objDAO.Update(obj);
        }

        public string Delete(
        String DTB,
        String LOOKUP_CATEGORY,
        String CODE
        )
        {
            return _objDAO.Delete(
            DTB,
            LOOKUP_CATEGORY,
            CODE
            );
        }
        public Boolean IsExist(
        String DTB,
        String LOOKUP_CATEGORY,
        String CODE
        )
        {
            return _objDAO.IsExist(
            DTB,
            LOOKUP_CATEGORY,
            CODE
            );
        }

        public DataTable Search(String columnName, String columnValue, String condition, String tableName, ref String sErr)
        {
            return _objDAO.Search(columnName, columnValue, condition, tableName, ref  sErr);
        }
        public string InsertUpdate(LIST_LOOKUPInfo obj)
        {
            string sErr = "";
            if (IsExist(
            obj.DTB,
            obj.LOOKUP_CATEGORY,
            obj.CODE
            ))
            {
                sErr = Update(obj);
            }
            else
                Add(obj, ref sErr);
            return sErr;
        }

        public DataTable GetTransferOut(string dtb, object from, object to, ref string sErr)
        {
            return _objDAO.GetTransferOut(dtb, from, to, ref sErr);
        }

        public DataTable ToTransferInStruct()
        {
            LIST_LOOKUPInfo inf = new LIST_LOOKUPInfo();
            return inf.ToDataTable();
        }

        public string TransferIn(DataRow row)
        {
            LIST_LOOKUPInfo inf = new LIST_LOOKUPInfo(row);
            return InsertUpdate(inf);
        }
        #endregion Method


        public int GetCountRecord(string db, string cate, ref string sErr)
        {
            return _objDAO.GetCountRecord(db, cate, ref  sErr);
        }

        public LIST_LOOKUPInfo GetByPos(string db, string cate, int pos, ref string sErr)
        {
            return _objDAO.GetByPos(db, cate, pos, ref  sErr);
        }
        public DataTable Get_Category_View(
                String DTB,
                String LOOKUP_CATEGORY,

                ref string sErr)
        {
            return _objDAO.Get_Category_View(
            DTB,
            LOOKUP_CATEGORY,

            ref sErr);
        }
    }
}
